﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class RTBattle : MonoBehaviour {

	private static RTBattle instance;
	
	public static RTBattle Instance{
		get{
			return instance;
		}
	}	
	
	void Awake()
	{
		instance = this;
	}

	public RTPawnManifest mainCharManifest;

	void Update()
	{
		if(Input.GetMouseButtonDown(0))
		{
			RaycastHit hit;
			int mask = 1 << LayerMask.NameToLayer("Ground") | 1 << LayerMask.NameToLayer("Pawn");
			Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
			if(Physics.Raycast(ray, out hit, 100, mask) )
			{
				Debug.Log("raycast  "+hit.collider.gameObject.name);
				RTPawnManifest targetManifest = hit.collider.gameObject.GetComponent<RTPawnManifest>();
				if(targetManifest!=null)
				{
					if(targetManifest!=mainCharManifest)
						mainCharManifest.AttackTo(targetManifest);
				}
				else
					mainCharManifest.MoveTo(hit.point);
			}
		}
	}
}
